var gulp = require('gulp');
var shell = require('gulp-shell');

// [Neo] TODO change here
const project_name = 'cqjy';
const docker_web_name = project_name + '_web_1';
const web_path = '/srv/http/' + project_name + '-web/';

const nginx_server_conf_path = '/etc/nginx/default.d/' + project_name;
const nginx_reload_cmd = 'sudo systemctl reload nginx';
var nginx_root = '/srv/http';
var nginx_html_path = '/usr/share/nginx/html';
var nginx_html_path_mac = '/usr/local/var/www';

gulp.task('default', shell.task([
  'npm run dev'
]));

gulp.task('build', shell.task([
  'npm run build',
  '7za a -r ' + project_name + '.zip ./dist/*',
]));

gulp.task('zip', shell.task([
  '7za a -r ' + project_name + '.zip ./dist/*',
]));

gulp.task('scp', shell.task([
  'scp ./' + project_name + '.zip zyh@' + project_name + '.jnaw.top:',
]));

gulp.task('zyh', shell.task([
  'npm run build',
  '7za a -r ' + project_name + '.zip ./dist/*',
  'scp ./' + project_name + '.zip zyh@' + project_name + '.jnaw.top:',
]));

gulp.task('init', shell.task([
  'if [ ! -e ' + nginx_root
  + ' ]; then if [ "Linux" = $(uname) ]; then sudo ln -s ' + nginx_html_path
  + ' ' + nginx_root + '; else sudo mkdir -p /srv; sudo ln -s '
  + nginx_html_path_mac + ' ' + nginx_root + '; fi; else if [ ! -L '
  + nginx_root + ' ]; then echo ' + nginx_root
  + ' check failed!; exit 1; fi; fi',
  'sudo mkdir -p ' + web_path,
  'sudo mkdir -p ' + nginx_server_conf_path,
]));

gulp.task('deploy', shell.task([
  'npm run build',
  'sudo cp -R ./dist/* ' + web_path,
  'sudo find ' + web_path + ' -type d -exec chmod +755 {} \\;',
]));

gulp.task('log', shell.task([
  'docker logs -f --tail 200 ' + docker_web_name,
]));




